import os
import sys
from datetime import datetime

# 定义文件夹名称的数组
folder_names = [

"VirtualCompanion",
"OutfitChange",
"ImageMakeover",

]


# 定义默认输出路径
output_path = os.getcwd()  # 默认是当前目录

# 检查是否有传入路径参数
if len(sys.argv) > 1:
    # 获取传入的路径参数
    input_path = sys.argv[1]

    # 检查路径是否存在
    if not os.path.exists(input_path):
        # 记录错误日志并退出
        error_message = f"Error: The specified path '{input_path}' does not exist."
        with open("error_log.txt", "a") as log_file:
            log_file.write(f"{datetime.now()} - {error_message}\n")
        print(error_message)
        sys.exit(1)
    else:
        # 如果路径存在，则设置为输出路径
        output_path = input_path

# 创建文件夹并输出成功的结果
for folder_name in folder_names:
    folder_path = os.path.join(output_path, folder_name)
    try:
        os.makedirs(folder_path, exist_ok=True)
        
        # 在文件夹内创建 `.gitkeep` 文件
#        gitkeep_path = os.path.join(folder_path, ".gitkeep")
#        with open(gitkeep_path, "w") as f:
#            f.write("")  # 创建一个空的 .gitkeep 文件
#        print(f"Successfully created folder: {folder_path} with .gitkeep")
        
        print(f"Successfully created folder: {folder_path}")
    except Exception as e:
        # 如果出现错误，则记录日志
        error_message = f"Error creating folder '{folder_name}': {str(e)}"
        with open("error_log.txt", "a") as log_file:
            log_file.write(f"{datetime.now()} - {error_message}\n")
        print(error_message)
